package com.ruoyi.web.controller.yuelao;

import cn.zwmas.web.feign.AccountFeign;
import cn.zwmas.web.vo.InfoVoApi;
import cn.zwmas.web.vo.PageVo;
import com.ruoyi.common.enums.ResponseStatus;
import com.ruoyi.system.domain.vo.BaseResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/yuelao")
public class YueLaoController {

    @Autowired
    private AccountFeign accountFeign;

    @GetMapping("/suggestConsoleList")
    @PreAuthorize("@ss.hasPermi('yuelao:suggestConsoleList')")
    public BaseResponse<PageVo<InfoVoApi>> suggestConsoleList(
            @RequestParam(name = "pageNo", required = false, defaultValue = "1" ) int pageNo,
            @RequestParam(name = "pageSize",required = false,defaultValue = "10" ) int pageSize){
        BaseResponse<PageVo<InfoVoApi>> response = buildSuccessData();
        PageVo<InfoVoApi> res = accountFeign.suggestConsoleList(pageNo, pageSize);
        response.setData(res);
        return response;
    }

    @GetMapping("/pullUserIdToSuggest")
    @PreAuthorize("@ss.hasPermi('yuelao:pullUserIdToSuggest')")
    public BaseResponse<Boolean> pullUserIdToSuggest(
            @RequestParam(name = "userId", required = false, defaultValue = "1" ) Long userId,
            @RequestParam(name = "score", required = false, defaultValue = "1" ) Integer score){
        BaseResponse<Boolean> response = buildSuccessData();
        Boolean res = accountFeign.pullUserIdToSuggest(userId,score);
        response.setData(res);
        return response;
    }

    @GetMapping("/delUserIdFromSuggest")
    @PreAuthorize("@ss.hasPermi('yuelao:delUserIdFromSuggest')")
    public BaseResponse<Boolean> delUserIdFromSuggest(
            @RequestParam(name = "userId", required = false, defaultValue = "1" )  Long userId){
        BaseResponse<Boolean> response = buildSuccessData();
        Boolean res = accountFeign.delUserIdFromSuggest(userId);
        response.setData(res);
        return response;
    }

    @GetMapping("/user/getInfoList")
    @PreAuthorize("@ss.hasPermi('yuelao:getInfoList')")
    public BaseResponse<PageVo<InfoVoApi>> getInfoList(
            @RequestParam(name = "type",required = false,defaultValue = "0")int type,
            @RequestParam(name = "gender",required = false,defaultValue = "0") int gender,
            @RequestParam(name = "pageNo",required = false,defaultValue = "1" ) int pageNo,
            @RequestParam(name = "pageSize",required = false,defaultValue = "10" ) int pageSize,
            @RequestParam(name = "id",required = false,defaultValue = "1") String id){
        BaseResponse<PageVo<InfoVoApi>> response = buildSuccessData();
        PageVo<InfoVoApi> res = accountFeign.getInfoList(type,gender,pageNo,pageSize,id);
        response.setData(res);
        return response;
    }

    @GetMapping("/user/updateUserInfo/{openId}/{type}/{message}")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('yuelao:user:updateUserInfo')")
    public BaseResponse<Boolean> updateConsoleUserInfo(@PathVariable("openId") String openId,
                                  @PathVariable(name = "message",required = false) String message,
                                  @PathVariable("type") int type){
        BaseResponse<Boolean> response = buildSuccessData();
        Boolean res = accountFeign.updateConsoleUserInfo(openId,message,type);
        response.setData(res);
        return response;
    }

    /**
     * 构造返回成功的响应对象
     *
     * @param
     * @return
     */
    protected <D> BaseResponse<D> buildSuccessData() {
        BaseResponse<D> response = new BaseResponse<>();
        response.setStatus(ResponseStatus.SUCCESS.ordinal());
        return response;
    }

}
